home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / win / wpause.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-04  |  9.0 KB  |  298 lines

  1. #ifndef lint    )Ø    *LSid = "$Id: wpause.c,v 1.3 1998/12/04 15:16:46 lhecking Exp $";
  2. #endif
  3.  
  4. /* GNUPLOT - win/wpause.c */
  5. /*[
  6.  * Copyright 1992, 1993, 1998   Russell Lang
  7.  *
  8.  * Permission to use, copy, and distribute this software and its
  9.  * documentation for any purpose with or without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and
  11.  * that both that copyright notice and this permission notice appear
  12.  * in supporting documentation.
  13.  *
  14.  * Permission to modify the software is granted, but not the right to
  15.  * distribute the complete modified source code.  Modifications are to
  16.  * be distributed as patches to the released version.  Permission to
  17.  * distribute binaries produced by compiling modified sources is granted,
  18.  * provided you
  19.  *   1. distribute the corresponding source modifications from the
  20.  *    released version in the form of a patch file along with the binaries,
  21.  *   2. add special version identification to distinguish your version
  22.  *    in addition to the base release version number,
  23.  *   3. provide your name and address as the primary contact for the
  24.  *    support of your modified version, and
  25.  *   4. retain our contact information in regard to use of the base
  26.  *    software.
  27.  * Permission to distribute the released version of the source code along
  28.  * with corresponding source modifications in the form of a patch file is
  29.  * granted with same provisions 2 through 4 for binary distributions.
  30.  *
  31.  * This software is provided "as is" without express or implied warranty
  32.  * to the extent permitted by applicable law.
  33. ]*/
  34.  
  35. /*
  36.  * AUTHORS
  37.  * 
  38.  *   Russell Lang
  39.  * 
  40.  * Send your comments or suggestions to 
  41.  *  info-gnuplot@dartmouth.edu.
  42.  * This is a mailing list; to join it send a note to 
  43.  *  majordomo@dartmouth.edu.  
  44.  * Send bug reports to
  45.  *  bug-gnuplot@dartmouth.edu.
  46.  */
  47. /* PauseBox() */
  48.  
  49. /* MessageBox ALWAYS appears in the middle of the screen so instead */
  50. /* we use this PauseBox so we can decide where it is to be placed */
  51.  
  52. #define STRICT
  53. #include <windows.h>
  54. #include <windowsx.h>
  55. #include <string.h>
  56. #include "wgnuplib.h"
  57. #include "wresourc.h"
  58. #include "wcommon.h"
  59.  
  60. /* Pause Window */
  61. LRESULT CALLBACK WINEXPORT WndPauseProc(HWND, UINT, WPARAM, LPARAM);
  62. LRESULT CALLBACK WINEXPORT PauseButtonProc(HWND, UINT, WPARAM, LPARAM);
  63.  
  64. /* Create Pause Class */
  65. /* called from PauseBox the first time a pause window is created */
  66. void
  67. CreatePauseClass(LPPW lppw)
  68. {
  69.     WNDCLASS wndclass;
  70.  
  71.     wndclass.style = 0;
  72.     wndclass.lpfnWndProc = (WNDPROC)WndPauseProc;
  73.     wndclass.cbClsExtra = 0;
  74.     wndclass.cbWndExtra = sizeof(void FAR *);
  75.     wndclass.hInstance = lppw->hInstance;
  76.     wndclass.hIcon = NULL;
  77.     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  78.     wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  79.     wndclass.lpszMenuName = NULL;
  80.     wndclass.lpszClassName = szPauseClass;
  81.     RegisterClass(&wndclass);
  82. }
  83.  
  84. /* PauseBox */
  85. int WDPROC
  86. PauseBox(LPPW lppw)
  87. {
  88.     MSG msg;
  89.     HDC hdc;
  90.     int width, height;
  91.     TEXTMETRIC tm;
  92.     RECT rect;
  93.  
  94.     if (!lppw->hPrevInstance)
  95.         CreatePauseClass(lppw);
  96.     GetWindowRect(GetDesktopWindow(), &rect);
  97.     if ( (lppw->Origin.x == CW_USEDEFAULT) || (lppw->Origin.x == 0) )
  98.         lppw->Origin.x = (rect.right + rect.left) / 2;
  99.     if ( (lppw->Origin.y == CW_USEDEFAULT) || (lppw->Origin.y == 0) )
  100.         lppw->Origin.y = (rect.bottom + rect.top) / 2;
  101.  
  102.     hdc = GetDC(NULL);
  103.     SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  104.     GetTextMetrics(hdc, &tm);
  105.     width  = max(24,4+_fstrlen(lppw->Message)) * tm.tmAveCharWidth;
  106.     width = min(width, rect.right-rect.left);
  107.     height = 28 * (tm.tmHeight + tm.tmExternalLeading) / 4;
  108.     ReleaseDC(NULL,hdc);
  109.  
  110. #ifndef WIN32
  111.     lppw->lpfnPauseButtonProc = 
  112. #ifdef __DLL__
  113.         (WNDPROC)GetProcAddress(hdllInstance, "PauseButtonProc");
  114. #else
  115.         (WNDPROC)MakeProcInstance((FARPROC)PauseButtonProc ,hdllInstance);
  116. #endif
  117. #endif
  118.     lppw->hWndPause = CreateWindowEx(WS_EX_DLGMODALFRAME, 
  119.         szPauseClass, lppw->Title,
  120. /* HBB 981202: WS_POPUPWINDOW would have WS_SYSMENU in it, but we don't
  121.  * want, nor need, a System menu in our Pause windows. Actually, it was
  122.  * emptied manually, in the WM_CREATE handler below, in the original code.
  123.  * This solution seems cleaner. */
  124.         WS_POPUP | WS_BORDER | WS_CAPTION,
  125.         lppw->Origin.x - width/2, lppw->Origin.y - height/2,
  126.         width, height,
  127.         lppw->hWndParent, NULL, lppw->hInstance, lppw);
  128.     ShowWindow(lppw->hWndPause, SW_SHOWNORMAL);
  129.     BringWindowToTop(lppw->hWndPause);
  130.     UpdateWindow(lppw->hWndPause);
  131.  
  132.     lppw->bPause = TRUE;
  133.     lppw->bPauseCancel = IDCANCEL;
  134.     while (lppw->bPause)
  135.             while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  136.             /* wait until window closed */
  137.                 TranslateMessage(&msg);
  138.                 DispatchMessage(&msg);
  139.             }
  140.     DestroyWindow(lppw->hWndPause);
  141. #ifndef WIN32
  142. #ifndef __DLL__
  143.     FreeProcInstance((FARPROC)lppw->lpfnPauseButtonProc);
  144. #endif
  145. #endif
  146.  
  147.     return(lppw->bPauseCancel);
  148. }
  149.  
  150. LRESULT CALLBACK WINEXPORT
  151. WndPauseProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  152. {
  153.     HDC hdc;
  154.     PAINTSTRUCT ps;
  155.     RECT rect;
  156.     TEXTMETRIC tm;
  157.     LPPW lppw;
  158.     int cxChar, cyChar, middle;
  159.  
  160.     lppw = (LPPW)GetWindowLong(hwnd, 0);
  161.  
  162.     switch(message) {
  163.         case WM_KEYDOWN:
  164.             if (wParam == VK_RETURN) {
  165.                 if (lppw->bDefOK)
  166.                     SendMessage(hwnd, WM_COMMAND, IDOK, 0L);
  167.                 else
  168.                     SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
  169.             }
  170.             return(0);
  171.         case WM_COMMAND:
  172.             switch(LOWORD(wParam)) {
  173.                 case IDCANCEL:
  174.                 case IDOK:
  175.                     lppw->bPauseCancel = LOWORD(wParam);
  176.                     lppw->bPause = FALSE;
  177.                     break;
  178.             }
  179.             return(0);
  180.         case WM_SETFOCUS:
  181.             SetFocus(lppw->bDefOK ? lppw->hOK : lppw->hCancel);
  182.             return(0);
  183.         case WM_PAINT:
  184.             {
  185.             hdc = BeginPaint(hwnd, &ps);
  186.             SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  187.             SetTextAlign(hdc, TA_CENTER);
  188.             GetClientRect(hwnd, &rect);
  189.             SetBkMode(hdc,TRANSPARENT);
  190.             TextOut(hdc,(rect.right+rect.left)/2, (rect.bottom+rect.top)/6,
  191.                 lppw->Message,_fstrlen(lppw->Message));
  192.             EndPaint(hwnd, &ps);
  193.             return 0;
  194.             }
  195.         case WM_CREATE:
  196.             {
  197.             /* HBB 981202 HMENU sysmenu = GetSystemMenu(hwnd, FALSE); */
  198.             lppw = ((CREATESTRUCT FAR *)lParam)->lpCreateParams;
  199.             SetWindowLong(hwnd, 0, (LONG)lppw);
  200.             lppw->hWndPause = hwnd;
  201.             hdc = GetDC(hwnd);
  202.             SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  203.             GetTextMetrics(hdc, &tm);
  204.             cxChar = tm.tmAveCharWidth;
  205.             cyChar = tm.tmHeight + tm.tmExternalLeading;
  206.             ReleaseDC(hwnd,hdc);
  207.             middle = ((LPCREATESTRUCT) lParam)->cx / 2;
  208.             lppw->hOK = CreateWindow((LPSTR)"button", (LPSTR)"OK",
  209.                 WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
  210.                     middle - 10*cxChar, 3*cyChar,
  211.                     8*cxChar, 7*cyChar/4,
  212.                     hwnd, (HMENU)IDOK,
  213.                     ((LPCREATESTRUCT) lParam)->hInstance, NULL);
  214.             lppw->bDefOK = TRUE;
  215.             lppw->hCancel = CreateWindow((LPSTR)"button", (LPSTR)"Cancel",
  216.                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  217.                     middle + 2*cxChar, 3*cyChar,
  218.                     8*cxChar, 7*cyChar/4,
  219.                     hwnd, (HMENU)IDCANCEL,
  220.                     ((LPCREATESTRUCT) lParam)->hInstance, NULL);
  221.             lppw->lpfnOK = (WNDPROC) GetWindowLong(lppw->hOK, GWL_WNDPROC);
  222. #ifdef WIN32
  223.             SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)PauseButtonProc);
  224. #else
  225.             SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
  226. #endif
  227.             lppw->lpfnCancel = (WNDPROC) GetWindowLong(lppw->hCancel, GWL_WNDPROC);
  228. #ifdef WIN32
  229.             SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)PauseButtonProc);
  230. #else
  231.             SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
  232. #endif
  233.             if (GetParent(hwnd))
  234.                 EnableWindow(GetParent(hwnd),FALSE);
  235. #if 0 /* HBB 981203 */
  236.             DeleteMenu(sysmenu,SC_RESTORE,MF_BYCOMMAND);
  237.             DeleteMenu(sysmenu,SC_SIZE,MF_BYCOMMAND);
  238.             DeleteMenu(sysmenu,SC_MINIMIZE,MF_BYCOMMAND);
  239.             DeleteMenu(sysmenu,SC_MAXIMIZE,MF_BYCOMMAND);
  240.             DeleteMenu(sysmenu,SC_TASKLIST,MF_BYCOMMAND);
  241.             DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
  242.             DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
  243. #endif
  244.             }
  245.             return 0;
  246.         case WM_DESTROY:
  247.             GetWindowRect(hwnd, &rect);
  248.             lppw->Origin.x = (rect.right+rect.left)/2;
  249.             lppw->Origin.y = (rect.bottom+rect.top)/2;
  250.             lppw->bPause = FALSE;
  251.             if (GetParent(hwnd))
  252.                 EnableWindow(GetParent(hwnd),TRUE);
  253.             break;
  254.     }
  255.     return DefWindowProc(hwnd, message, wParam, lParam);
  256. }
  257.  
  258.  
  259. LRESULT CALLBACK WINEXPORT
  260. PauseButtonProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  261. {
  262.     LPPW lppw;
  263. #ifdef WIN32
  264.     LONG n = GetWindowLong(hwnd, GWL_ID);
  265. #else
  266.     WORD n = GetWindowWord(hwnd, GWW_ID);
  267. #endif
  268.     lppw = (LPPW)GetWindowLong(GetParent(hwnd), 0);
  269.     switch(message) {
  270.         case WM_KEYDOWN:
  271.             switch(wParam) {
  272.               case VK_TAB:
  273.               case VK_BACK:
  274.               case VK_LEFT:
  275.               case VK_RIGHT:
  276.               case VK_UP:
  277.               case VK_DOWN:
  278.                 lppw->bDefOK = !(n == IDOK);
  279.                 if (lppw->bDefOK) {
  280.                     SendMessage(lppw->hOK,     BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)TRUE);
  281.                     SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, (LPARAM)TRUE);
  282.                     SetFocus(lppw->hOK);
  283.                 }
  284.                 else {
  285.                     SendMessage(lppw->hOK,     BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, (LPARAM)TRUE);
  286.                     SendMessage(lppw->hCancel, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, (LPARAM)TRUE);
  287.                     SetFocus(lppw->hCancel);
  288.                 }
  289.                 break;
  290.               default:
  291.                 SendMessage(GetParent(hwnd), message, wParam, lParam);
  292.             }
  293.             break;
  294.     }
  295.     return CallWindowProc(((n == IDOK) ? lppw->lpfnOK : lppw->lpfnCancel),
  296.          hwnd, message, wParam, lParam);
  297. }
  298.